package cn.itcast.mapper;

import cn.itcast.entity.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    @Options(keyProperty = "id" , useGeneratedKeys = true)
    @Insert("insert into hotel.order (user_id,room_id,status,check_in_number,nores,cash_pledge,cash_pledge_status,check_in_date,check_out_date,expected_check_out_date,create_time,update_time) " +
            " values " +
            "(#{userId},#{roomId},#{status},#{checkInNumber},#{nores},#{cashPledge},#{cashPledgeStatus},#{checkInDate},#{checkOutDate},#{expectedCheckOutDate},#{createTime},#{updateTime})")
     void addOrder(Order order);


    @Select("select * from hotel.order where room_id = #{roomId} ;")
    Integer getOrderCashPledge(Long roomId);


    List<Order> getOrderDay(LocalDateTime endDate, LocalDateTime beginDate);

    @Select("select * from hotel.order where user_id = #{userId} and check_out_date < NOW()")
    List<Order> getOrderUserId(Integer userId);

    @Select("select * from hotel.order where room_id = #{roomId} and status = #{status}")
    Order getOrderByRoomId(Long roomId, Integer status);


    void updateOrder(Order order);



    Order serviceOrder(Order order);
}

